<template>
  <div style="border: 1px solid #ccc">
    <Toolbar
      style="border-bottom: 1px solid #ccc"
      :editor="editor"
      :defaultConfig="toolbarConfig"
      :mode="mode"
    />
    <Editor
      style="height: 500px; overflow-y: hidden"
      v-model="content"
      :defaultConfig="editorConfig"
      :mode="mode"
      @onCreated="onCreated"
      @customPaste="customPaste"
    />
  </div>
</template>

<script>
import { Editor, Toolbar } from "@wangeditor/editor-for-vue";
import { editorConfig, customPaste } from "./index";
// import { DomEditor } from "@wangeditor/editor";
export default {
  name: "RichText",
  components: { Editor, Toolbar },
  data() {
    return {
      editor: null,
      content: "<p>hello</p>",
      toolbarConfig: {},
      editorConfig,
      mode: "default",
    };
  },
  mounted() {
    // setTimeout(() => {
    //   const toolbar = DomEditor.getToolbar(this.editor);
    //   const curToolbarConfig = toolbar.getConfig();
    //   console.log(curToolbarConfig.toolbarKeys); // 当前菜单排序和分组
    // }, 1000);
  },
  methods: {
    customPaste,
    onCreated(editor) {
      this.editor = Object.seal(editor); // 一定要用 Object.seal() ，否则会报错
    },
  },
  beforeDestroy() {
    const editor = this.editor;
    if (editor == null) return;
    editor.destroy(); // 组件销毁时，及时销毁编辑器
  },
};
</script>

<style lang="less" scoped></style>
